/*
 * @Author: 13558093597 277098906@qq.com
 * @Date: 2025-06-26 15:24:57
 * @LastEditors: 13558093597 277098906@qq.com
 * @LastEditTime: 2025-06-26 15:25:10
 * @FilePath: \mes_app\lib\ui\scroll_refresh_config.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

/// 配置滚动
class ScrollRefreshConfig extends StatelessWidget {
  final Widget child;

  final RefreshController refreshController;

  final bool enablePullUp;

  final bool enablePullDown;

  final VoidCallback? onRefresh;

  final VoidCallback? onLoading;

  final Axis scrollDirection;

  const ScrollRefreshConfig(
      {super.key,
      required this.child,
      required this.refreshController,
      this.enablePullUp = true,
      this.enablePullDown = true,
      this.scrollDirection = Axis.vertical,
      this.onLoading,
      this.onRefresh});

  @override
  Widget build(BuildContext context) {
    return RefreshConfiguration(
      headerBuilder: () => const ClassicHeader(
        idleText: '下拉刷新',
        refreshingText: '刷新中...',
        completeText: '加载成功',
        releaseText: '松开立即刷新',
        failedText: '刷新失败',
      ),
      // 配置默认头部指示器,假如你每个页面的头部指示器都一样的话,你需要设置这个，这里设置成比较常见的效果
      footerBuilder: () => const ClassicFooter(
        idleText: '上拉加载',
        loadingText: '加载中…',
        canLoadingText: '松手开始加载数据',
        failedText: '加载失败',
        noDataText: '没有更多数据了',
      ),
      // 配置默认底部指示器
      headerTriggerDistance: 50,
      // 头部触发刷新的越界距离
      footerTriggerDistance: 30,
      //底部触发刷新的越界距离,距离底部多少开始刷新
      springDescription:
          const SpringDescription(stiffness: 170, damping: 16, mass: 1.9),
      //弹性参数，劲度系数、阻尼、质量
      maxOverScrollExtent: 100,
      //头部最大可以拖动的范围,如果发生冲出视图范围区域,请设置这个属性
      maxUnderScrollExtent: 0,
      // 底部最大可以拖动的范围，0默认底部不能往上拖拽
      enableScrollWhenRefreshCompleted: true,
      //这个属性不兼容PageView和TabBarView,如果你特别需要TabBarView左右滑动,你需要把它设置为true
      enableLoadingWhenFailed: true,
      //在加载失败的状态下,用户仍然可以通过手势上拉来触发加载更多
      hideFooterWhenNotFull: false,
      // Viewport不满一屏时,禁用上拉加载更多功能
      enableBallisticLoad: true,
      // 可以通过惯性滑动触发加载更多
      child: SmartRefresher(
        controller: refreshController,
        enablePullUp: enablePullUp,
        enablePullDown: enablePullDown,
        onRefresh: onRefresh,
        onLoading: onLoading,
        scrollDirection: scrollDirection,
        child: child,
      ),
    );
  }
}
